<template>
  <div class="login-page">
    <!-- 头部 -->

    <van-nav-bar title="登陆" />

    <!-- 表单 -->

    <van-form @submit="onSubmit">
      <!-- input -->
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="请输入用户名"
        :rules="[
          {required:true,message:'用户名不能为空'},
          // 正则表达式 检验格式  [] {} . * W w ......
          // ^abc  --->  abcabdkfhdkfjh
          // abc$  --->  3748yf7y4r47abc
          // ^abc[0-9]$  --->  abc7
          // w word >= 5
          {pattern:/^\w{5,}$/ , message:'用户名至少包含5个字符'}
        ]"
      />

      <van-field
        v-model="password"
        name="password"
        label="密码"
        placeholder="请输入密码"
        :rules="[
          {required:true,message:'密码不能为空'},
          {pattern:/^\w{7,}$/ , message:'密码长度错误!'}
        ]"
      />

      <div style="margin-top: 20px;">
        <van-button type="info" navtive-type="submit">提交</van-button>
      </div>
    </van-form>

    <!-- 没有账号去注册 -->
    <router-link class="link" to="/register">没有账号 , 去注册</router-link>
  </div>
</template>

<script>

export default {
  name: 'LoginPage',
  data () {
    return {
      username: '',
      password: ''
    }
  },

  methods: {
    // 监听表单的提交 (参数位置能拿到 表单的值)
    onSubmit (values) {
      // async  await axios
      console.log('submit', values)
    }
  }
}
</script>
